package io.vincentwinner.systeminfoapi.api;

import com.alibaba.fastjson.JSONObject;
import io.vincentwinner.systeminfoapi.dao.IMemoryDao;
import io.vincentwinner.systeminfoapi.service.IDynamicInfoService;
import io.vincentwinner.systeminfoapi.service.IStaticInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/memory")
public class MemoryController {

    @Resource(name = "staticInfoService")
    private IStaticInfoService staticInfoService;

    @Resource(name = "dynamicInfoService")
    private IDynamicInfoService dynamicInfoService;

    @Resource(name = "memoryDao")
    private IMemoryDao memoryDao;

    @RequestMapping
    public Object root(){
        JSONObject memoryDynamicInfo = dynamicInfoService.getMemoryDynamicInfo();
        memoryDynamicInfo.put("memoryChips",staticInfoService.getMemoryStaticInfo());
        return memoryDynamicInfo;
    }

    @RequestMapping("/static")
    public Object static$(){
        return staticInfoService.getMemoryStaticInfo();
    }

    @RequestMapping("/dynamic")
    public Object dynamic(){
        return dynamicInfoService.getMemoryDynamicInfo();
    }

    @RequestMapping("/memoryNum")
    public Object totalMemoryNum(){
        return memoryDao.getMemoryNum();
    }

    @RequestMapping("/physicalTotal")
    public Object physicalTotal(){
        return memoryDao.getPhysicalTotal();
    }

    @RequestMapping("/physicalFree")
    public Object physicalFree(){
        return memoryDao.getPhysicalFree();
    }

    @RequestMapping("/physicalUsed")
    public Object physicalUsed(){
        return memoryDao.getPhysicalUsed();
    }

    @RequestMapping("/physicalUsage")
    public Object physicalUsage(){
        return memoryDao.getPhysicalUsage();
    }

    @RequestMapping("/swapTotal")
    public Object swapTotal(){
        return memoryDao.getSwapTotal();
    }

    @RequestMapping("/swapFree")
    public Object swapFree(){
        return memoryDao.getSwapFree();
    }

    @RequestMapping("/swapUsed")
    public Object swapUsed(){
        return memoryDao.getSwapUsed();
    }

    @RequestMapping("/swapUsage")
    public Object swapUsage(){
        return memoryDao.getSwapUsage();
    }
}
